﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using System.Reflection;
using System.Windows.Forms;
using Scrt;
namespace WordAddIn2010
{
    public partial class Ribbon
    {
        SoftMgr _SftMgr;
        private void Ribbon_Load(object sender, RibbonUIEventArgs e)
        {
            gValue.WordApp = Globals.ThisAddIn.Application;
            _SftMgr = new SoftMgr();
            _SftMgr.InitRibbon(this);
            gValue.RegRsult = gValue.SoftReg.RegResult;
            _SftMgr.StrtBackground();
        }

        /// <summary>
        /// 关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Ribbon_Close(object sender, EventArgs e)
        {
            _SftMgr = null;
        }
        /// <summary>
        /// 用户手册
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUserGuid_Click(object sender, RibbonControlEventArgs e)
        {
            _SftMgr.ShowUserGuidFile();
        }

        private void btnAboutAuthor_Click(object sender, RibbonControlEventArgs e)
        {
            string strInfo = "";
            string strVer = "V" + Funcs.GetSftVersion().ToString();
            strInfo = "作者：我是菜鸟\n版本：" + strVer;
            MessageBox.Show(strInfo, gValue.MSG_TITLE);
        }

        private void btnHomeUrl_Click(object sender, RibbonControlEventArgs e)
        {
            gValue.SoftReg.ShowHomePage();
        }

        private void btnRegister_Click(object sender, RibbonControlEventArgs e)
        {
            _SftMgr.RegSft();
        }

        private void btnUserGuid_Click_1(object sender, RibbonControlEventArgs e)
        {
            _SftMgr.ShowUserGuidFile();
        }

        private void btnPurchase_Click(object sender, RibbonControlEventArgs e)
        {
            _SftMgr.OpenUrl(gValue.URL_ITEM_PURCHASE);
        }

        private void btnCheckUpdate_Click(object sender, RibbonControlEventArgs e)
        {
            if (!Funcs.CheckNetConnection())
            {
                MessageBox.Show("请检查网络连接",gValue.MSG_TITLE,MessageBoxButtons.OK);
                return;
            }
            SoftwareUpdateInfor updateInfo = _SftMgr.CheckUpdate();
            if (updateInfo.NeedUpdate)
            {
                string str = string.Format("当前版本:V{0}\r\n升级版本:V{1}\r\n\r\n是否打开升级网址?", updateInfo.CurrentVersion, updateInfo.UpdateVersion);
                if (MessageBox.Show(str,gValue.MSG_TITLE, MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    _SftMgr.OpenUrl(updateInfo.UpdateUrl);
                    _SftMgr.SetDisHasNewVersion(false);
                }
            }
            else
            {
                MessageBox.Show("该软件已经为最新", gValue.MSG_TITLE, MessageBoxButtons.OK);
            }
        }

        private void btnHasNewVersion_Click(object sender, RibbonControlEventArgs e)
        {
            if (gValue.SftwareDownloadUrl != "")
            {
                _SftMgr.OpenUrl(gValue.SftwareDownloadUrl);
                _SftMgr.SetDisHasNewVersion(false);
            }
        }

    }
}
